home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / vol_200 / 255_01 / vpmodule.asm < prev    next >
Assembly Source File  |  1988-03-28  |  6KB  |  171 lines

  1.           page   80,132
  2.           page
  3. ;
  4. ;       EGA Graphic Primitive for Microsoft C 3.0, Version 01APR86.
  5. ;       (C) 1986 by Kent Cedola, 2015 Meadow Lake Ct., Norfolk, VA, 23518
  6. ;
  7.  
  8. dpl       struc
  9. flags     db     ?
  10. device    db     ?
  11. width     dw     ?
  12. height    dw     ?
  13. w_inch    dw     ?
  14. h_inch    dw     ?
  15. colors    dw     ?
  16. palettes  dw     ?
  17. initrd    dw     ?
  18. readrw    dw     ?
  19. termrd    dw     ?
  20. initwt    dw     ?
  21. writrw    dw     ?
  22. termwt    dw     ?
  23. link      dw     ?
  24. segment   dw     ?
  25. pages     dw     ?
  26. dpl       ends
  27.  
  28. dgroup    group  _data
  29.  
  30. _data     segment word public 'data'
  31.           assume ds:dgroup
  32.  
  33. _vdwritbp dw     0
  34. _vdwritb1 db     0
  35. _vdwritb2 db     0
  36. _vdwritw1 dw     0
  37. _vdwritw2 dw     0
  38. _vdwritw3 dw     0
  39.  
  40. vdpl      db     01h                   ; Flags
  41.           db     'V'                   ; Device
  42.           dw     ?                     ; Width
  43.           dw     ?                     ; Height
  44.           dw     1                     ; W_inch
  45.           dw     1                     ; H_inch
  46.           dw     ?                     ; Colors
  47.           dw     ?                     ; Palettes
  48.           dw     offset _text:_vpinitrd  ; Initrd
  49.           dw     offset _text:_vpreadrw  ; Readrw
  50.           dw     offset _text:_vptermrd  ; Termrd
  51.           dw     offset _text:_vpinitwt  ; Initwt
  52.           dw     offset _text:_vpwritrw  ; Writrw
  53.           dw     offset _text:_vptermwt  ; Termwt
  54.           dw     0                     ; Link
  55.           dw     ?                     ; Segment
  56.           dw     ?                     ; Pages
  57.  
  58.  
  59.  
  60. _data     ends
  61.  
  62. _text     segment byte public 'code'
  63.  
  64.           assume cs:_text,ds:dgroup
  65.           public _vpinit,_vpterm
  66.           public _vpinitrd,_vpreadrw,_vptermrd
  67.           public _vpinitwt,_vpwritrw,_vptermwt
  68.  
  69.           page
  70.  
  71.     dpl = vpinit(x,y,bits);
  72.  
  73. _vpinit   proc   near
  74.  
  75.           push   bp
  76.           mov    bp,sp
  77.           push   si
  78.  
  79.           mov    ax,32                 ; Allocate 32 bytes of memory for DPL
  80.           push   ax                    ;   Store number of bytes (32) on stack
  81.           call   _malloc               ;   Call C's memory allocation function
  82.           add    sp,2                  ;   Restore Stack
  83.           or     ax,ax                 ;   Check for "Out of Memory" condition
  84.           jz     initerr               ;     Jump on error (Out of Memory)
  85.  
  86.           mov    di,ax                 ; Initialize new DPL (pointer in SI)
  87.           push   di                    ;   Save pointer of DPL for later
  88.           lea    si,vdpl               ;   Copy standard pattern to new DPL
  89.           mov    cx,16                 ;     Set counter for DPL size in words
  90.           push   ds                    ;     Copy DS to ES
  91.           pop    es                    ;       ...
  92.           rep movsw                    ;     Perform the copy operation
  93.  
  94.           pop    si                    ; Restore DPL into SI
  95.  
  96.           mov    ax,[bp+4]             ; Load width and copy to DPL
  97.           mov    [si].width,ax         ;   ...
  98.           mov    ax,[bp+6]             ; Load height and copy to DPL
  99.           mov    [si].height,ax        ;   ...
  100.           mov    ax,[bp+8]             ; Load bits and copy to DPL
  101.           mov    [si].colors,ax        ;   ...
  102.           mov    [si].palettes,ax      ;   ...
  103.  
  104.           mul    [si].width            ; Determine width in bytes
  105.           add    ax,[si].palettes      ;   ... = (width * bits + bits - 1) / 8
  106.           dec    ax                    ;   ...
  107.           shr    ax,1                  ;   ...
  108.           shr    ax,1                  ;   ...
  109.           shr    ax,1                  ;   ...
  110.  
  111.           mul    [si].height           ; Determine number of bytes needed
  112.  
  113.           div    sixteen               ; Determine number of paragraphs needed
  114.           mov    [si].pages,ax         ;   Copy to DPL
  115.  
  116.  
  117.  
  118.  
  119. ;****
  120.           mov    ax,[bp].buffer
  121.           mov    _xdwritbp,ax
  122.           cmp    [bp].dir,0
  123.           jnz    bottotop
  124. toptobot:
  125.           mov    ax,5
  126.           mov    _xdwritw2,ax
  127.           mov    ax,[bp].y_coor
  128.           jmp    short cont
  129. bottotop:
  130.           mov    ax,-5
  131.           mov    _xdwritw2,ax
  132.           mov    ax,[bp].y_coor
  133.           add    ax,[bp].y_len
  134.           dec    ax
  135. cont:
  136.           mov    cx,ax
  137.           shl    ax,1
  138.           shl    ax,1
  139.           add    ax,cx
  140.           add    ax,_gdgseg
  141.           mov    dx,[bp].x_coor
  142.           mov    cx,dx
  143.           shr    dx,1                  ;   X / 8;
  144.           shr    dx,1                  ;   ...
  145.           shr    dx,1                  ;   ...
  146.           add    ax,dx
  147.           mov    _xdwritw1,ax
  148.  
  149.           mov    al,80h                ; Compute mask byte to first bit
  150.           and    cl,7                  ;   ...  (It has to be done this way to
  151.           ror    al,cl                 ;   ...   use merge value in write)
  152.           mov    _xdwritb1,al          ;   ...
  153.  
  154.           mov    ax,[bp].x_len
  155.           mov    _xdwritw3,ax
  156.  
  157.           mov    dx,03CEh              ; Load graphic controller's address port
  158.           mov    ah,_GDMERGE
  159.           mov    al,3
  160.           out    dx,ax
  161.           mov    ax,0205h
  162.           out    dx,ax
  163.  
  164.           pop    bp
  165.           ret
  166.  
  167. _gpinitwt endp
  168.  
  169. _text     ends
  170.           end
  171.